package com.niit.onlinemusicserver34.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.onlinemusicserver34.common.R;
import com.niit.onlinemusicserver34.mapper.SingerMapper;
import com.niit.onlinemusicserver34.model.domain.Consumer;
import com.niit.onlinemusicserver34.model.domain.Singer;
import com.niit.onlinemusicserver34.model.request.SingerRequest;
import com.niit.onlinemusicserver34.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SingerServiceImpl extends ServiceImpl<SingerMapper,Singer> implements SingerService {

    @Autowired
    SingerMapper singerMapper;

    @Override
    public R listAll() {
        return R.success("查询成功",singerMapper.selectList(null));
    }

    @Override
    public R saveSinger(SingerRequest singerRequest) {
//        Singer singer = new Singer();
//        BeanUtils.copyProperties(singerRequest,singer);
        return R.success("添加成功",singerMapper.insert(singerRequest));
    }

    @Override
    public R deleteSinger(Integer id) {
        return R.success("删除成功",singerMapper.deleteById(id));
    }

    @Override
    public R updateSinger(SingerRequest singerRequest) {
        return R.success("更新成功",singerMapper.updateById(singerRequest));
    }

    @Override
    public R getBySex(Byte sex) {
        // where name = ? and password = ?
        QueryWrapper<Singer> wrapper =  new QueryWrapper<>();
        wrapper.eq("sex",sex);
        return R.success("查询成功",singerMapper.selectList(wrapper));
    }
}
